package com.guigu.www.service.imp;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.www.mapper.GatherMapper;
import com.guigu.www.pojo.Gather;
import com.guigu.www.service.GatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GatherServiceImpl extends ServiceImpl<GatherMapper, Gather> implements GatherService {
    //获取map
    @Autowired
    GatherMapper gatherMapper;
    @Override
    //查询所以的入库要审核的产品
    public IPage queryGatherAll(int pageno, int pagesize) {
        Page page=new Page(pageno,pagesize);
        QueryWrapper<Gather> queryWrapper=new QueryWrapper<Gather>();
        queryWrapper.eq("check_tag","S001-0");
        return this.page(page,queryWrapper);
    }
    //查询所以要申请的入库的产品
    @Override
    public Gather queryGatherById(int id) {
        return gatherMapper.queryGatherById(id);
    }

    @Override
    //审核入库产品是否通过
    public boolean updateGaherById(Gather gather) {
        return gatherMapper.updateGaherById(gather)>0?true:false;
    }
    //查询所以的入库申请查询
    @Override
    public IPage<Gather> queryByGaherAllShow(int pageno,int pagesize) {
        //创建Page
        Page page=new Page(pageno,pagesize);
        QueryWrapper<Gather> queryWrapper=new QueryWrapper<Gather>();
        return this.page(page,queryWrapper);
    }
    //根据流水号查询入库的产品申请单
    @Override
    public Gather queryGaherBygatherId(String gatherId) {
        return gatherMapper.queryGaherBygatherId(gatherId);
    }
    //根据流水号查询入库的产品申请单
    @Override
    public Gather queryGaherBygatherIds(String gatherId) {
        return gatherMapper.queryGaherBygatherIds(gatherId);
    }

    @Override
    public IPage<Gather> queryBywarehousin(int pageno, int pagesize) {
        //获取page
        Page page=new Page(pageno,pagesize);
        //获取query
        QueryWrapper<Gather> queryWrapper=new QueryWrapper<Gather>();
        //设置条件
        queryWrapper.eq("gather_tag","K002-2");
        return this.page(page,queryWrapper);
    }
    //根据登记的入库单号查询对应的入库数据 入库明细数据
    @Override
    public Gather queryByGatherGatherdetailswarhousing(String gatherId) {
        return gatherMapper.queryByGatherGatherdetailswarhousing(gatherId);
    }

    @Override
    //登记 修改状态
    public boolean updateWarehosingGaher(Gather gather) {
        return gatherMapper.updateWarehosingGaher(gather)>0?true:false;
    }

    @Override
    public IPage<Gather> queryByWarehousingexaminepage(int pageno, int pagesize) {
        //创建pageno
        Page page=new Page(pageno,pagesize);
        //设置条件
        QueryWrapper<Gather> queryWrapper=new QueryWrapper<Gather>();
        queryWrapper.eq("gather_tag","K002-3");
        return this.page(page,queryWrapper);
    }

    @Override
    public boolean updatewarehousingexaminequeryGatherByGathers(Gather gather) {
        if(Double.parseDouble(gather.getAmountSum())==Double.parseDouble(gather.getGatheredAmountSum())){
            gather.setGatherTag("K002-4");
        }else {
            gather.setGatherTag("K002-2");
        }
        return gatherMapper.updatewarehousingexaminequeryGatherByGathers(gather)>0?true:false;
    }
    //查询所以登记过的产品
    @Override
    public IPage<Gather> queryGatherallwarehousing(int pageno, int pagesize) {
        //创建page
        Page page=new Page(pageno,pagesize);
        //设置条件
        QueryWrapper<Gather> queryWrapper=new QueryWrapper<Gather>();
        queryWrapper.notIn("gather_tag","K002-1");
        return this.page(page,queryWrapper);
    }

    //查询所以入库产品通过的产品
    @Override
    public IPage<Gather> queryBydispatgather(int pageno, int pagesize) {
        //创建page
        Page page=new Page(pageno,pagesize);
        //设置条件
        QueryWrapper<Gather> queryWrapper=new QueryWrapper<Gather>();
        queryWrapper.eq("check_tag","S001-1");
        return this.page(page,queryWrapper);
    }
    //调度成功 修改状态
    @Override
    public boolean updateGatherBygatherId(String gatherId) {
        return gatherMapper.updateGatherBygatherId(gatherId)>0?true:false;
    }
}
